/**
 * 测试demo
 * @param {*} data  数据
 */
export const test = (data) => {
	return data
};

/**
 * 处理 null 数据处理 
 * @param {*} data  原始数据值
 * @param {*} callback_data 返回数据类型
 */
export const handle_null = (data, callback_data) => {
	if (!data && typeof (data) != 'undefined' && data != 0) {
		return callback_data
	} else {
		return data
	}
};


/**
 * 钱包地址 安全隐藏
 * @param {*} str 钱包地址
 * @param {*} hide 星号数量
 * @param {*} before 前面显示数量
 * @param {*} after 后面显示数量
 * @returns 
 */
export const walletAddressHide = (str, hide = 6, before = 6, after = 6) => {
	let star = ''
	for (let i = 0; i < hide; i++) {
		star += '*'
	}
	let front = str.substring(0, before);
	let behind = str.substring(str.length - after, str.length);
	return `${front}${star}${behind}`;
};

/**
 * 日期格式转换
 * @param {*} date 
 * @returns 
 */
export const transformDate = (date) => {
	var y = date.getFullYear()
	var m = date.getMonth() + 1
	m = m < 10 ? '0' + m : m
	var d = date.getDate()
	d = d < 10 ? '0' + d : d
	var h = date.getHours()
	h = h < 10 ? '0' + h : h
	var minute = date.getMinutes()
	minute = minute < 10 ? '0' + minute : minute
	var second = date.getSeconds()
	second = second < 10 ? '0' + second : second
	return y + '-' + m + '-' + d
	// return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
}
/**
 * 获取随技术
 * @param {Number} min 最小 
 * @param {Number} max 最大
 */
export const getRandom = (min, max) => {
	return Math.floor(Math.random() * (max - min + 1)) + min;
}


/**
 * 16进制的字符串 转换为整数
 * @param {*} hex 
 * @returns 
 */
export const hex2int = (hex) => {
	var len = hex.length, a = new Array(len), code;
	for (var i = 0; i < len; i++) {
		code = hex.charCodeAt(i);
		if (48 <= code && code < 58) {
			code -= 48;
		} else {
			code = (code & 0xdf) - 65 + 10;
		}
		a[i] = code;
	}

	return a.reduce(function (acc, c) {
		acc = 16 * acc + c;
		return acc;
	}, 0);
}

/**
 * 十进制整数转换16进制
 * @param {*} hex 
 * @returns 
 */
export const int2hex = (hex) => {
	var hex = "0123456789abcdef";
	var s = "";
	while (num) {
		s = hex.charAt(num % 16) + s;
		num = Math.floor(num / 16);
	}
	if (typeof width === "undefined" || width <= s.length) {
		return "0x" + s;
	}
	var delta = width - s.length;
	var padding = "";
	while (delta-- > 0) {
		padding += "0";
	}
	return "0x" + padding + s;
}




/**
 * 判断系统源 是ios 还是安卓
 */
export const appSource = () => {
	const u = navigator.userAgent;
	const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
	if (isiOS) {
		return "ios";
	} else {
		return "andriod";
	}
}